﻿#include "stdafx.h"

namespace DuiLib {
CChildLayoutUI::CChildLayoutUI()
{

}

void CChildLayoutUI::Init()
{
    if (!m_pstrXMLFile.IsEmpty())
    {
        CDialogBuilder builder;
        CContainerUI *pChildWindow = static_cast<CContainerUI *>(builder.Create(m_pstrXMLFile.GetData(), (UINT)0,
                                                                 NULL, m_pManager));

        if (pChildWindow)
        {
            this->Add(pChildWindow);
        }
        else
        {
            this->RemoveAll();
        }
    }
}

void CChildLayoutUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
    if (_tcscmp(pstrName, _T("xmlfile")) == 0) { SetChildLayoutXML(ParseString(pstrValue)); }
    else if (_tcscmp(pstrName, _T("autowidth")) == 0) { DUITRACE(_T("不支持属性:autowidth")); }
    else if (_tcscmp(pstrName, _T("autoheight")) == 0) { DUITRACE(_T("不支持属性:autoheight")); }
    else { CContainerUI::SetAttribute(pstrName, pstrValue); }
}

void CChildLayoutUI::SetChildLayoutXML(CDuiString pXML)
{
    m_pstrXMLFile = pXML;
}

CDuiString CChildLayoutUI::GetChildLayoutXML()
{
    return m_pstrXMLFile;
}

LPVOID CChildLayoutUI::GetInterface(LPCTSTR pstrName)
{
    if (_tcscmp(pstrName, DUI_CTR_CHILDLAYOUT) == 0) { return static_cast<CChildLayoutUI *>(this); }

    return CControlUI::GetInterface(pstrName);
}

LPCTSTR CChildLayoutUI::GetClass() const
{
    return DUI_CTR_CHILDLAYOUT;
}
} // namespace DuiLib
